package com.gzsxy.JUC.unsafe;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 并发修改异常ConcurrentModificationException
 */
public class MapTest {
    //map是这样用的
    public static void main(String[] args) {
//        Map<String, Object> map = new HashMap<>();
//        Map<String, Object> map =  Collections.synchronizedMap(new HashMap<>());
        Map<String, Object> map = new ConcurrentHashMap<>();


        for (int i = 1; i < 30; i++) {
            new Thread(() -> {
                map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0, 5));
                System.out.println(map);
            }, String.valueOf(i)).start();
        }


    }
}
